package com.broada.apm.service;

import java.util.HashMap;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.broada.apm.ajax.AlertResult;
import com.broada.apm.model.Threshold;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("apm/alarms")
@Api(value = "apm/alarms", description = "告警相关的APIs")
@Produces(MediaType.APPLICATION_JSON)
public interface AlarmService {
	/**
	 * 查询时间段内最新告警
	 * 
	 * @param appId
	 * @param nodeId
	 * @param rows
	 * @return
	 */
	@GET
	@Path("/latest")
	@ApiOperation(value = "查询时间段内最新告警")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult queryLatestAlarmByType(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId,
			@ApiParam(value = "服务节点id或交易类型id", required = true) @QueryParam("id") String id,
			@ApiParam(value = "告警类型", required = false) @QueryParam("type") String type,
			@ApiParam(value = "每页显示查询记录条数", required = true) @QueryParam("rows") int rows,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "用以区分交易模式和非交易模式，其值可为system或business", required = true) @QueryParam("panelId") String panelId,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	/**
	 * 
	 * @param happentimeBegin
	 *            开始时间
	 * @param happentimeEnd
	 *            结束时间
	 * @param alarmType
	 *            告警类型
	 * @param serviceName
	 *            告警源服务名称
	 * @param alarmStatu
	 *            告警确认状态
	 * @param alaremKeyword
	 *            告警关键字
	 * @return
	 */
	@GET
	@Path("/alarmsData")
	@ApiOperation(value = "告警台查询告警")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult queryAlarms(
			@ApiParam(value = "告警等级，可为50（严重），20（警告），10（提醒）", required = true) @QueryParam("severity") int serverity,
			@ApiParam(value = "告警类型", required = false) @QueryParam("type") String type,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("firstTime") Long firstTime,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("lastTime") Long lastTime,
			@ApiParam(value = "告警来源", required = false) @QueryParam("source") String source,
			@ApiParam(value = "处理状态， -1（全部），0（新告警），1（已恢复）", required = false) @QueryParam("status") int status,
			@ApiParam(value = "告警状态， -1（全部），0（未处理），1（已确认），2（已清除）", required = false) @QueryParam("clearStatus") int clearStatus,
			@ApiParam(value = "关键词", required = false) @QueryParam("key") String key,
			@ApiParam(value = "排序字段", required = false) @QueryParam("sortField") String sortField,
			@ApiParam(value = "排序顺序，升序或降序，asc或desc", required = true) @QueryParam("sortBy") String sortBy,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex,
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize);

	/**
	 * 告警等级数据字典查询
	 * 
	 * @return
	 */
	@GET
	@Path("/alarmsRank")
	@ApiOperation(value = "告警等级数据字典查询")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult queryAlertServerity();

	/**
	 * 告警等级对应的告警数查询
	 * 
	 * @return
	 */
	@GET
	@Path("/alarmsRankNum")
	@ApiOperation(value = "各个告警等级对应的告警数查询")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult queryAlertStaticBySeverity();

	/**
	 * 告警等级对应的告警数查询
	 * 
	 * @return
	 */
	@GET
	@Path("/alarmsWorstNum")
	@ApiOperation(value = "严重告警等级对应的告警数查询")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult queryAlertCountByWorstSeverity();

	/**
	 * 删除告警
	 * 
	 * @return
	 */
	@DELETE
	@Path("/alarms")
	@ApiOperation(value = "删除告警")
	@Produces(MediaType.APPLICATION_JSON)
	public AlertResult delAlarms(
			@ApiParam(value = "需要删除的告警的id", required = true) @QueryParam("alarmIds") String alarmIds);

	/**
	 * 修改告警状态
	 * 
	 * @return
	 */
	@PUT
	@Path("/alarms")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "修改告警状态")
	public AlertResult updAlarms(
			@ApiParam(value = "需要修改告警状态的告警id以及告警状态，提交形式类似于：{alarmIds: \"iudi41aa-3272,iudi41aa-6843\", status: 1}", required = true) HashMap<String, String> alarmIds);

	/**
	 * 告警阀值配置
	 * 
	 * @param appId
	 * @param threshold
	 * @return
	 */
	@POST
	@Path("/{appId}/{panelId}/thresholds")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警阈值配置")
	public AlertResult saveThreshold(
			@ApiParam(value = "需要配置告警阈值的应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "设置的告警阈值", required = true) Threshold threshold,
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);

	/**
	 * 告警阀值配置更新
	 * 
	 * @param appId
	 * @param threshold
	 * @return
	 */
	@PUT
	@Path("/{appId}/thresholds/{panelId}")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警阀值配置更新")
	public AlertResult updateThreshold(
			@ApiParam(value = "需要更新告警阈值的应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "更新的告警阈值", required = true) Threshold threshold,
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);

	/**
	 * 告警阀值配置编辑查询
	 * 
	 * @param appId
	 * @param targetId
	 * @return
	 */
	@GET
	@Path("/{appId}/{targetId}/{panelId}/thresholds")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警阀值配置编辑查询")
	public AlertResult queryThresholdByTargetId(
			@ApiParam(value = "所要查询的阈值所属的应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "所要查询的阈值所属的服务节点或交易类型id", required = true) @PathParam("targetId") String targetId,
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);

	/**
	 * 告警阀值配置列表查询
	 * 
	 * @param appId
	 * @return
	 */
	@GET
	@Path("/{appId}/thresholds/{panelId}")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警阀值配置列表查询")
	public AlertResult queryThresholdsByApplicationId(
			@ApiParam(value = "需要查询的告警阈值的应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId);

	/**
	 * 告警阀值配置删除
	 * 
	 * @param appId
	 * @param targetId
	 * @return
	 */
	@DELETE
	@Path("/{appId}/thresholds/{targetId}/{panelId}/{thresholdType}")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警阀值配置删除")
	public AlertResult deleteThresholdsByTargetId(
			@ApiParam(value = "需要删除的告警阈值的应用系统id", required = true) @PathParam("appId") String appId,
			@ApiParam(value = "需要删除的告警阈值的服务节点或交易类型id", required = true) @PathParam("targetId") String targetId,
			@ApiParam(value = "用以区分交易模式和非交易模式，可为system或business", required = true) @PathParam("panelId") String panelId,
			@ApiParam(value = "告警类型", required = true) @PathParam("thresholdType") String thresholdType);

	/**
	 * 告警等级对应的主机数查询
	 * 
	 * @return
	 */
	@GET
	@Path("/serviceCount")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "告警等级对应的主机数查询")
	public AlertResult queryServerCountByWorstSeverity();
}
